# coding: utf-8
module ApplicationHelper

	def curpath
		self.controller_name + '#' + self.action_name
	end

	def getTitle
		return @page_title if(@page_title != nil)
		path = self.controller_name + '#' + self.action_name
		return '用户登录_天天笔记' if(path == 'user#login')
		return '用户注册_天天笔记' if(path == 'user#reg')
		return '意见箱_天天笔记' if(path == 'suggestion#index')
		return '更新计划_天天笔记' if(path == 'suggestion#plan')
		return '关于我们_天天笔记' if(path == 'suggestion#about')
		return '日历_万年历_农历在线查询_天天笔记' if(path == 'suggestion#rili')
		return '修改密码_天天笔记' if(path == 'user#profile')
		return '新建文档_文档_天天笔记' if(request.url.include? 'doc/new')
		return '修改文档_文档_天天笔记' if(request.url.include? 'doc/edit')
		return @doc.title << '_文档库_天天笔记' if(request.url.include? 'doc/share')
		return '文档库_天天笔记' if(self.controller_name == 'doc')
		return '便笺_天天笔记' if(self.controller_name == 'memo')
		'【天天笔记】网络记事本_在线电子记事本软件'
	end

	def getKeywords
		return '' if (request.url.include? '/doc/share/')
		path = self.controller_name + '#' + self.action_name
		return '<meta name="keywords" content="记事本,网络记事本,在线记事本" />' if(path == 'user#index' || path == 'user#login' || path == 'suggestion#about' || path == 'doc#share')
		return '<meta name="keywords" content="便笺,网络便笺" />' if(path == 'memo#index')
		return '<meta name="keywords" content="日历,万年历,农历查询,阳历,阴历,在线日历,天天笔记在线日历" />' if(path == 'suggestion#rili')
	end

	def getDesc
		path = self.controller_name + '#' + self.action_name
		return '<meta name="description" content="天天笔记是当前国内最好用的网络记事本、在线电子记事本软件，包括文档、便笺、日记本、收藏夹等服务，功能简洁、操作方便、每天备份数据，并且支持手机浏览，让您随时随地拥有云笔记服务。" />' if(path == 'user#index')
		return '<meta name="description" content="欢迎使用天天笔记在线日历功能，它可以查询万年历、阴历、阳历、国际时间、节气、节日、假期等，是您生活的好帮手。" />' if(path == 'suggestion#rili')
	end

	# 导航链接样式
	def nav_class(name)
		path = self.controller_name + '/' + self.action_name
		return 'tab' if(path == 'suggestion/about')
		return 'tab active' if(path.include? name)
		return 'tab'
	end
	
	# 是否显示友情链接
	def showlinks
		path = self.controller_name + '#' + self.action_name
		case path
		when 'user#login' then true
		when 'suggestion#index' then true
		else false
		end
	end

	# 获取最终页的链接地址
	def getDetailUrl(doc)
		id = DocBll.encode(doc[:id]).to_s
		"/doc/show/#{id}a.html"
	end

	# 获取共享文档的链接地址
	def getShareUrl(doc)
		url = ''
		begin

			# 兼容旧版url
			if(doc[:id] < 311)
				return "/doc/share/#{doc[:userid]}/#{doc[:id]}.html"
			end

			# 新版url开始：
			docid = doc[:id].to_s

			# 获取加密串
			v0 = doc[:userid].to_s << '__' << docid
			v1 = Digest::MD5.hexdigest(v0)
			v2 = v1.reverse
			randcode = v2[2, 12]

			# 拼接地址
			url = '/doc/share/' << randcode << '_' << docid << '.html'
		rescue Exception => e
			logger.error e
		end
		url
	end	


	# 判断是否为手机访问
	def mobileUser?
		result = false
		ua = request.env["HTTP_USER_AGENT"]
		if(ua != nil)
			r = ua.downcase.match(/(untrusted|nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|wap|mobile|iphone|ucweb|zxwap)/)
			result = r != nil
		end
		result
	end
end
